package org.sbbs.base.jsf;

import org.joinfaces.primefaces.SpringDataJpaLazyDataModel;
import org.primefaces.model.FilterMeta;
import org.springframework.data.jpa.repository.JpaRepository;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jenkins
 * @param <R>
 */
@SuppressWarnings("unchecked")
public class SbbsJpaLazyDataModel<R extends JpaRepository> extends SpringDataJpaLazyDataModel implements Serializable {

    private static final long serialVersionUID = 3774966695846507474L;

    public SbbsJpaLazyDataModel(R repository) {
        super(repository);
    }

    public Map<String, FilterMeta> preProcessFilterBy(Map<String, FilterMeta> filterBy) {
        return filterBy;
    }

    @Override
    public List load(int first, int pageSize, Map sortBy, Map filterBy) {
        filterBy = this.preProcessFilterBy(filterBy);
        return super.load(first, pageSize, sortBy, filterBy);
    }

    @Override
    public int count(Map filterBy) {
        filterBy = this.preProcessFilterBy(filterBy);
        return super.count(filterBy);
    }
}
